import Vue from 'vue'

import {
	RouterMount,
	createRouter
} from 'uni-simple-router';

import {
	ACCESS_TOKEN
} from '@/common/util/constants.js'

const router = createRouter({
	platform: process.env.VUE_APP_PLATFORM,
	routes: [...ROUTES]
});

const whiteList = ['/pages/login/login','/pages/index/index','/pages/diary/diary','/pages/mine/mine','/pages/lesson/index']
//全局路由前置守卫
router.beforeEach((to, from, next) => {
	//判断是否校验路由
	let token = uni.getStorageSync(ACCESS_TOKEN);
	if (token) {
		next()
	} else {
		if (whiteList.indexOf(to.path) !== -1) {
			next()
		} else {
			next({
				path: "/pages/login/login",
				query: {
					redirect: to.name
				}
			});
		}
	}
})
// 全局路由后置守卫
router.afterEach((to, from) => {
	console.log("afterEach")
})
export {
	router,
	RouterMount
}
